/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worldscale.xp.wslib.im.jabber;

import java.io.IOException;
import org.w3c.dom.Element;

/**
 *
 * @author Kun
 */
public interface JabberClient {

    public static final int PHASE_UNLOGIN = 0;
    public static final int PHASE_LOGIN = 1;
    public static final int PHASE_ONLINE = 2;
    public static final int PHASE_OFFLINE = 3;

    public static interface PhaseListener {

        void onPhaseChanged(int oldPhase, int newPhase);
    }

    public static interface StreamListener {

        void onStreamOpen();

        void onStreamClose();

        void onStanza(Element stanza);
    }

    public static interface RosterManager {

        void saveRoster(JabberID owner, Element roster);

        Element loadRoster(JabberID owner);
    }

    public static interface LoginContext {

        JabberID getJID();

        String getPassword();

        String getServer();

        int getPort();

        boolean isUseSSL();
    }

    public static interface Dispatcher {

        void openStream(String host) throws IOException;

        void closeStream() throws IOException;

        void send(byte[] buf) throws IOException;

        void send(byte[] buf, int off, int len) throws IOException;

        void send(String str) throws IOException;
    }

    void addStreamListener(StreamListener sl);

    void removeStreamListener(StreamListener sl);

    void addPhaseListener(PhaseListener pl);

    void removePhaseListener(PhaseListener pl);

    void setRosterManager(RosterManager rm);

    boolean login(LoginContext lc);

    void logout();

    int getPhase();

    Dispatcher getDispatcher();

    void close();

    JabberRosterModel getRosterModel();

    JabberMessageList getMessageList();

    JabberID getLocalJID();
}
